<?php

namespace App\Http\Controllers\Home;


use App\Model\Comcheckdetaillog;
use App\Model\Comcheckdetailself;
use App\Model\Comcheckdetailselflog;
use App\Model\Comcheckgroupself;
use App\Model\Comcheckself;
use App\Model\Comcheckselfstep;
use App\Model\Comwordslog;
use App\Model\Comwordsselflog;
use Illuminate\Support\Facades\Auth;
use PhpOffice\PhpWord\TemplateProcessor;

use App\Http\Controllers\Controller;

use App\Model\Checkgroup;
use App\Model\Checknegative;
use App\Model\Checkaccord;
use App\Model\Checkcommand;
use App\Model\Company;
use App\Model\Comcheck;
use App\Model\Comcheckdetail;
use App\Model\Checkentry;
use App\Model\Comcheckstep;
use App\Model\Comcheckgroup;
use App\Model\Area;
use App\Model\Comsafeofficer;
use App\User;
use App\Services\ImageClass;
use App\Model\Commondata;
use App\Services\Export\WordChoose;

use App\Services\WordcheckdataselfClass;

use Illuminate\Http\Request;
use App\Http\Requests\CheckRequest;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\DB;

class NinecheckselfController extends Controller
{
    //选择人物环管
    public function choose(Request $request,int $status) {
        if($status > 4 || $status < 1) {
            \Session::flash('error', '参数错误!');
            return back();
        }
        $statusArray = [
            '1'=>'人的不安全行为',
            '2'=>'物的不安全状态',
            '3'=>'作业环境的缺陷',
            '4'=>'安全管理的缺陷',
        ];
        $title = $statusArray[$status];
        $request->session()->put('status',$status);
        $checkId = $request->session()->get('checkId',0);
        $type = $request->session()->get('firetype',0);
        $categoryId = $request->session()->get('categoryId',0);
        $where = ['categoryId'=>$categoryId,'status'=>$status,'type'=>$type];
        $comcheckgroup = new Comcheckgroupself();
        $groups = $comcheckgroup->getCheckgroup($checkId,$categoryId,$status,$type);
        return view('ninecheckself/choose')
            ->with('title',$title)
            ->with('type',$type)
            ->with('groups',$groups)
            ->with('status',$status);
    }

    //新增检查项
    public function creategroup(Request $request)
    {
        $firetype = $request->session()->get('firetype',0);

        $groups = $request->input('group');
        $status = $request->input('status');
        $companyId = $request->session()->get('companyId');
        if(!$firetype || !$companyId) {
            \Session::flash('error', '参数错误!');
            return back();
        }
        $comcheckInfo = Comcheckself::where(['companyId'=>$companyId])->select('id','status')->first();
        if($comcheckInfo) {
            $checkId = $comcheckInfo['id'];
        } else {
            $user = Auth::user();
            $check['companyId'] = $companyId;
            $check['created'] = date('Y-m-d H:i:s',time());
            $check['userId'] = $user->id;
            $checkId = Comcheckself::insertGetId($check);
        }

//        if($groups) {
//            foreach ($groups as $k => $v) {
//                $groups[$k]['checkId'] = $checkId;
//            }
//            Comcheckgroup::insert($groups);
//        }

        $step = [];
        $step['checkId'] = $checkId;
        $step['stepStatus'] = $status;
        $step['typeStatus'] = $firetype;
        $one = Comcheckselfstep::where(['checkId'=>$step['checkId'],'stepStatus'=>$step['stepStatus'],'typeStatus'=>$step['typeStatus']])->get();
        $one = json_decode(json_encode($one), true);
        if (empty($one)){Comcheckselfstep::insertGetId($step);}
        $checkStep = Comcheckselfstep::where(['checkId'=>$checkId,'typeStatus'=>$firetype])->get();
        $stepArray = ['1'=>1,'2'=>2,'3'=>3,'4'=>4];
        foreach ($checkStep as $k => $v) {
            unset($stepArray[$v->stepStatus]);
        }
        if(count($stepArray)) {
            foreach ($stepArray as $k) {
                return redirect('ninecheckself/choose/'.$k);
            }
        } else {
            return redirect('ninesmallself/choose/'.$firetype);
        }


    }

    public function finish(int $companyId)
    {
        $fire = 0;
        $nofire = 0;
        $comcheckstep = new Comcheckselfstep();
        $fireinfo = $comcheckstep->getfiretype($companyId);
        if(count($fireinfo)){
            foreach ($fireinfo as $k => $v) {
                if($v->typeStatus == 1) {
                    $fire += $v->stepStatus;
                }
                if($v->typeStatus == 2) {
                    $nofire += $v->stepStatus;
                }
            }
        }
        $company = Company::find($companyId);
        if(!$company) {
            \Session::flash('error', '公司信息有误!');
            return redirect('/ninesmallself/firetype/'.$companyId);
        }
        /**新增**/
        $comcheck = new Comcheckself();
        $checkinfo = $comcheck->where(['companyId'=>$companyId])->first();
        $checkdetaillog = Comcheckdetailselflog::where('checkId','=',$checkinfo->id)->orderBy('created_at','desc')->first();
//        $checkdetaillog = json_decode(json_encode($checkdetaillog), true);
//        if (!empty($yes)){
        if (!empty($checkdetaillog->created_at)){
            $yes =strtotime($checkdetaillog->created_at)>($checkinfo->wordsTime)?true:false;
        }else{
            $yes = false;
        }
        $comcheckupdate = Comcheckself::where('id','=',$checkinfo->id)->first();
        if (!empty($comcheckupdate->updated)){
            $insert =$comcheckupdate->updated>($checkinfo->wordsTime)?true:false;
        }else{
            $insert = false;
        }
        if (!$yes && !$insert)
        {
            $yess = true;
        }else{
            $yess = false;

        }
        /**新增**/
        if($company['scheduleself'] >= 2 && $yess) {
//            dd('ss');
            return redirect('/ninecheckself/download/'.$companyId);
        }
        //获取初查隐患
        $detail = new Comcheckdetailself();
//        dd($checkinfo->id);
//        $comcheck = Comcheck::find($id);
        $infos = $detail->getInconform($checkinfo->id);
        $negatives = [];
        foreach ($infos as $k=>$v){
            if (!empty($v->negatives)){
                $arr = explode(',',$v->negatives);
                foreach ($arr as $ar){
                    if (!empty($ar)){
                        array_push($negatives,$ar);
                    }
                }
            }
        }
        $negatives = Checknegative::whereIn('id',$negatives)->get();
        return view('ninecheckself/finish')
            ->with('negatives',$negatives)
            ->with('companyId',$companyId);
    }



    //查看风险点
    public function show($groupId) {
        $groupInfo = Checkgroup::find($groupId);
        if(empty($groupInfo)){
            return back();
        }
        $is = $groupInfo->status;
        $type = $groupInfo->type;
        $title = $groupInfo->name;
        $entrys = Checkentry::where('groupId',$groupId)->get();
        return view('ninecheckself/show')
            ->with('groupId',$groupId)
            ->with('title',$title)
            ->with('is',$is)
            ->with('type',$type)
            ->with('entrys',$entrys);
    }


    //查看其他
    public function showelse($groupId) {
        $groupInfo = Checkgroup::find($groupId);

        if(empty($groupInfo)){
            return back();
        }
        $title = $groupInfo->name;
        $entrys = Checkentry::where('groupId',$groupId)->get();
        return view('ninecheckself/showelse')
            ->with('groupId',$groupId)
            ->with('title',$title)
            ->with('entrys',$entrys);
    }


    //检查项的提交
    public function create(CheckRequest $request) {
        $data = $request->all();
        $groupId = $request->input('groupId');
        $checkId = $request->session()->get('checkId',0);
        if(!$checkId)
        {
            return redirect('/choose');
        }
        $entryIds = $data['entryId'];
        $statuses = $data['status'];
        $isfires = $data['isfire'];
        $contents = $data['content'];
        $contentsexist = $data['contentexist'];
        $pictures = is_array($data['picture'])?$data['picture']:0;
        $negatives = isset($data['negative'])?$data['negative']:0;
        foreach ($entryIds as $k => $v) {
            $checkdetail[$k]['checkId'] = $checkId;
            $checkdetail[$k]['entryId'] = $v;
            $checkdetail[$k]['pictures'] = '';
            $checkdetail[$k]['groupId'] = $groupId;
        }
        foreach ($statuses as $k => $v) {
            $checkdetail[$k]['status'] = $v;
            if (!empty($contents[$k])){
                $checkdetail[$k]['status'] = 2;
            }
        }
        foreach ($contents as $k => $v) {
            $checkdetail[$k]['content'] = $v;
        }
        foreach ($isfires as $k => $v) {
            $checkdetail[$k]['isfire'] = $v;
        }
        foreach ($contentsexist as $k => $v) {
            $checkdetail[$k]['contentexist'] = $v;
        }
        if($pictures) {
            foreach ($pictures as $k => $v) {
                $checkdetail[$k]['pictures'] = $v;
            }
        }
        foreach ($checkdetail as $k => $v) {
            $checkdetail[$k]['negatives'] = '';
            if($negatives) {
                foreach ($negatives as $kk => $vv) {
                    if($v['entryId'] == $kk){
                        $checkdetail[$k]['negatives'] = $vv;
                    }
                }
            }
        }
        $firetype = Checkgroup::find($groupId)->type;
//        dd($checkdetail);
        $comCheckdetail = new Comcheckdetailself();
        foreach ($checkdetail as $k=>$v){
            if($v['isfire'] == 0){
                $one = Comcheckdetailself::where(['checkId'=>$v['checkId'],'groupId'=>$v['groupId'],'entryId'=>$v['entryId']])->get();
                $one = json_decode(json_encode($one), true);
                if (empty($one)){
                    Comcheckdetailself::insert($v);}
            }else{
                Comcheckdetailself::insert($v);
            }
//            }else{
//                return redirect('ninesmall/choose/'.$firetype);
//            }
        }
//        $comCheckdetail->addAll($checkdetail);
        Comcheckself::where('id','=',$checkId)->update(['updated'=>time()]);
        $status = Checkgroup::find($groupId)->status;
        $step = [];
        $step['checkId'] = $checkId;
        $step['stepStatus'] = $status;
        $step['typeStatus'] = $firetype;
        $one = Comcheckselfstep::where(['checkId'=>$step['checkId'],'stepStatus'=>$step['stepStatus'],'typeStatus'=>$step['typeStatus']])->get();
        $one = json_decode(json_encode($one), true);
        if (empty($one)){Comcheckselfstep::insertGetId($step);}
        // $this->exportWord1($checkId);
        return redirect('ninesmallself/choose/'.$firetype);
    }


    //其他检查项的提交
    public function createelse(CheckRequest $request) {
        $data = $request->all();
        $groupId = $request->input('groupId');
        $checkId = $request->session()->get('checkId',0);
        $status = $request->session()->get('status',0);
        $contents = $data['content'];
        $pictures = is_array($data['picture'])?$data['picture']:0;
        foreach ($contents as $k => $v) {
            $checkdetail[$k]['checkId'] = $checkId;
            $checkdetail[$k]['groupId'] = $groupId;
            $checkdetail[$k]['content'] = $v;
            if (empty($v)){
                $checkdetail[$k]['status'] = 1;
            }else{
                $checkdetail[$k]['status'] = 2;
            }
        }
        if($pictures) {
            foreach ($pictures as $k => $v) {
                $checkdetail[$k]['pictures'] = $v;
            }
        }
        $checkgroup['checkId'] = $checkId;
        $checkgroup['groupId'] = $groupId;
        $checkgroup['status'] = 1;
        /*使用事务插入*/
        DB::beginTransaction();
        try{
            $insert = Comcheckgroupself::insertGetId($checkgroup);
            if($insert) {
                DB::commit();
            }
        }catch (\Exception $e) {
            DB::rollBack();
//            \Session::flash('error', $e->getMessage());
            return redirect('ninecheckself/choose/'.$status);
        }
        $comCheckdetail = new Comcheckdetailself();
        $comCheckdetail->addAll($checkdetail);
        // $this->exportWord1($checkId);
        return redirect('ninecheckself/choose/'.$status);
    }


    public function update(Request $request,int $groupId){
        $checkId = $request->session()->get('checkId',0);
        $data = Comcheckdetailself::where(['checkId'=>$checkId,'groupId'=>$groupId])->get();
        $negatives = [];
        foreach ($data as $v){
            $arr = explode(",",$v->negatives);
            foreach ($arr as $v1){
                empty($v1)?'':array_push($negatives,$v1);
            }
        }
        $negatives = Checknegative::whereIn('id',$negatives)->get();

        $groupInfo = Checkgroup::find($groupId);
        if(empty($groupInfo)){
            return back();
        }
        $comcheckgroup = [];
        $comcheckgroup = Comcheckgroupself::where(['checkId'=>$checkId,'groupId'=>$groupId])->first();
        $entrys = Checkentry::where('groupId',$groupId)->get();
        $title = $groupInfo->name;
        $type = $groupInfo->type;
        return view('ninecheckself/update')
            ->with('data',$data)
            ->with('groupId',$groupId)
            ->with('entrys',$entrys)
            ->with('comcheckgroup',$comcheckgroup)
            ->with('negatives',$negatives)
            ->with('type',$type)
            ->with('title',$title);

    }
    public function updateelse(Request $request,int $groupId){
        $checkId = $request->session()->get('checkId',0);
        $data = Comcheckdetailself::where(['checkId'=>$checkId,'groupId'=>$groupId])->get();
//        $data = json_decode(json_encode($data), true);
//        dd($data);
        $negatives = [];
        foreach ($data as $v){
            $arr = explode(",",$v->negatives);
            foreach ($arr as $v1){
                empty($v1)?'':array_push($negatives,$v1);
            }
        }
        $negatives = Checknegative::whereIn('id',$negatives)->get();

        $groupInfo = Checkgroup::find($groupId);
        if(empty($groupInfo)){
            return back();
        }
        $comcheckgroup = [];
        $comcheckgroup = Comcheckgroupself::where(['checkId'=>$checkId,'groupId'=>$groupId])->first();
        $entrys = Checkentry::where('groupId',$groupId)->get();
        $title = $groupInfo->name;
        $ren= $comcheckgroup->ren;$caichan=$comcheckgroup->cai;$des = $comcheckgroup->des;
        return view('ninecheckself/updateelse')
            ->with('data',$data)
            ->with('groupId',$groupId)
            ->with('entrys',$entrys)
            ->with('ren',$ren)
            ->with('caichan',$caichan)
            ->with('des',$des)
            ->with('comcheckgroup',$comcheckgroup)
            ->with('negatives',$negatives)
            ->with('title',$title);

    }
    public function updatepost(Request $request){
        $data = $request->all();
        $groupId = $request->input('groupId');
        $firetype = Checkgroup::find($groupId)->type;
        $checkId = $request->session()->get('checkId',0);
        $status = $request->session()->get('status',0);
        if(!$checkId)
        {
            return redirect('/choose');
        }
        $entryIds = $data['entryId'];
        $ids = $data['id'];
        $statuses = $data['status'];
        $contents = $data['content'];
        $contentsexist = $data['contentexist'];
        $pictures = is_array($data['picture'])?$data['picture']:0;
        $negatives = isset($data['negative'])?$data['negative']:0;
        foreach ($entryIds as $k => $v) {
            $checkdetail[$k]['id'] = $ids[$k];
            $checkdetail[$k]['checkId'] = $checkId;
            $checkdetail[$k]['entryId'] = $v;
            $checkdetail[$k]['pictures'] = '';
            $checkdetail[$k]['groupId'] = $groupId;
        }
        foreach ($statuses as $k => $v) {
            $checkdetail[$k]['status'] = $v;
            if (empty($contents[$k]) && empty($entryIds[$k])){
                $checkdetail[$k]['status'] = 1;
            }
            if (!empty($contents[$k]) && empty($entryIds[$k])){
                $checkdetail[$k]['status'] = 2;
            }
        }
        foreach ($contents as $k => $v) {
            $checkdetail[$k]['content'] = $v;
        }
        foreach ($contentsexist as $k => $v) {
            $checkdetail[$k]['contentexist'] = $v;
        }
        if($pictures) {
            foreach ($pictures as $k => $v) {
                if (empty($v)){
                    $detail = Comcheckdetailself::where('id','=',$ids[$k])->get();
                    $detail = json_decode(json_encode($detail), true);
                    $checkdetail[$k]['pictures'] = $detail[0]['pictures'];
                }else{
                    $checkdetail[$k]['pictures'] = $v;
                }
            }
        }
        foreach ($checkdetail as $k => $v) {
            $checkdetail[$k]['negatives'] = '';
            if($negatives) {
                foreach ($negatives as $kk => $vv) {
                    if($v['entryId'] == $kk){
                        $checkdetail[$k]['negatives'] = $vv;
                    }
                }
            }
        }
        Comcheckself::where('id','=',$checkId)->update(['updated'=>time()]);
        $time = time();
        foreach ($checkdetail as $v){
            $result = Comcheckdetailself::where('id','=',$v['id'])->update($v);
            $old = Comcheckdetailself::where('id','=',$v['id'])->get();
            $old = json_decode(json_encode($old), true);
            $old[0]['created_at'] = $time;
            $comCheckdetaillog = new Comcheckdetailselflog();
            $comCheckdetaillog->addAll($old[0]);
        }
        return redirect('ninesmallself/choose/'.$firetype);
    }


    public function updateelsepost(Request $request){
        $data = $request->all();
        $groupId = $request->input('groupId');
        $ids = $request->input('id');
        $checkId = $request->session()->get('checkId',0);
        $status = $request->session()->get('status',0);
        $contents = $data['content'];
        $pictures = is_array($data['picture'])?$data['picture']:0;
        foreach ($contents as $k => $v) {
            $checkdetail[$k]['checkId'] = $checkId;
            $checkdetail[$k]['id'] = $ids[$k];
            $checkdetail[$k]['groupId'] = $groupId;
            $checkdetail[$k]['content'] = $v;
            if (empty($v)){
                $checkdetail[$k]['status'] = 1;
            }else{
                $checkdetail[$k]['status'] = 2;
            }
        }
        if($pictures) {
            foreach ($pictures as $k => $v) {
                if (empty($v)){
                    $detail = Comcheckdetailself::where('id','=',$ids[$k])->get();
                    $detail = json_decode(json_encode($detail), true);
                    $checkdetail[$k]['pictures'] = $detail[0]['pictures'];
                }else{
                    $checkdetail[$k]['pictures'] = $v;
                }
            }
        }
        Comcheckself::where('id','=',$checkId)->update(['updated'=>time()]);
        $time = time();
        foreach ($checkdetail as $v){
            $result = Comcheckdetailself::where('id','=',$v['id'])->update($v);
            $old = Comcheckdetailself::where('id','=',$v['id'])->get();
            $old = json_decode(json_encode($old), true);
            $old[0]['created_at'] = $time;
            $comCheckdetaillog = new Comcheckdetailselflog();
            $comCheckdetaillog->addAll($old[0]);
        }
        return redirect('ninecheckself/choose/'.$status);
    }


    public function signature(Request $request)
    {
        $companyId = $request->input('companyId');
        $comcheckInfo = Comcheckself::where(['companyId'=>$companyId])->select('id','status')->first();
        if(!$comcheckInfo) {
            return redirect('/ninesmallself/firetype/'.$companyId);
        }
        $lng = $request->input('lng')?:'120.370839';
        $lat = $request->input('lat')?:'36.128151';
        $userimgbase=$request->input('userimgbase');
        $comimgbase=$request->input('userimgbase');
        if(empty($userimgbase)) {
            \Session::flash('error', '未签名!');
            return back();
        }
        $imgclass = new ImageClass();
        $usersignature = $imgclass->base64toimg($userimgbase);
        $comsignature = $imgclass->base64toimg($userimgbase);
        $mapimg = $imgclass->maptoimg($lng,$lat);
        $update = [
            'usersignature'=>$usersignature,
            'comsignature'=>$comsignature,
            'lng'=>$lng,
            'lat'=>$lat,
            'mapimg'=>$mapimg,
        ];
        Comcheckself::where(['companyId'=>$companyId])->update($update);
        $wancheng = Company::where(['id'=>$companyId])->first();
        if ($wancheng->scheduleself >=2){

        }else{
            Company::where(['id'=>$companyId])->update(['scheduleself'=>2]);
        }

        return redirect('ninecheckself/download/'.$companyId);
    }
    public function downloadwords(int $companyId)
    {
        // $wordsUrl = $this->exportWord($companyId);
        $comcheck = new Comcheckself();
        $comCheckdetail = new Comcheckdetailself();
        $checkinfo = $comcheck->where(['companyId'=>$companyId])->first();
        $download = [];
        $wordsUrl = $checkinfo->wordsUrl;
        $checkdetaillog = Comcheckdetailselflog::where('checkId','=',$checkinfo->id)->orderBy('created_at','desc')->first();

        if (!empty($checkdetaillog->created_at)){
            $yes =strtotime($checkdetaillog->created_at)>($checkinfo->wordsTime)?true:false;
        }else{
            $yes = false;
        }
//        if(!$wordsUrl || $yes) {
//            $wordsUrl = $this->exportWord($companyId);
//            /***新增***/
//            $checkinfo->wordsUrl = $wordsUrl;
//            $checkinfo->wordsTime = time();
//
//            /***新增***/
//            $checkinfo->save();
//            $log = [];
//            $log['checkId'] = $checkinfo->id;
//            $log['wordUrl'] = $checkinfo->wordsUrl;
//            $log['comsignature'] = $checkinfo->comsignature;
//            $log['usersignature'] = $checkinfo->usersignature;
//            $log['created'] = time();
//            $result = Comwordslog::insert($log);
//        }
        $urlArray = explode(',', $wordsUrl);
        foreach ($urlArray as $k => $v) {
            $download[$k]['name'] = substr(strrchr($v,'/'),1,-18);
            $download[$k]['url'] = substr($v,1);
        }
        return view('ninecheckself/download')
            ->with('download',$download);
    }

    public function download(int $companyId)
    {
	    // $wordsUrl = $this->exportWord($companyId);
        $comcheck = new Comcheckself();
        $comCheckdetail = new Comcheckdetailself();
        $checkinfo = $comcheck->where(['companyId'=>$companyId])->first();
        $download = [];
        $wordsUrl = $checkinfo->wordsUrl;
        $checkdetaillog = Comcheckdetailselflog::where('checkId','=',$checkinfo->id)->orderBy('created_at','desc')->first();

        if (!empty($checkdetaillog->created_at)){
            $yes =strtotime($checkdetaillog->created_at)>($checkinfo->wordsTime)?true:false;
        }else{
            $yes = false;
        }
        $comcheckupdate = Comcheckself::where('id','=',$checkinfo->id)->first();
        if (!empty($comcheckupdate->updated)){
            $insert =$comcheckupdate->updated>($checkinfo->wordsTime)?true:false;
        }else{
            $insert = false;
        }
        if ($yes || $insert)
        {
            $yess = true;
        }else{
            $yess = false;

        }
//        dd($yess);
        if(!$wordsUrl || $yess) {
            $wordsUrl = $this->exportWord($companyId);
            /***新增***/
            $checkinfo->wordsUrl = $wordsUrl;
            $checkinfo->wordsTime = time();

            /***新增***/
            $checkinfo->save();
            $log = [];
            $log['checkId'] = $checkinfo->id;
            $log['wordUrl'] = $checkinfo->wordsUrl;
            $log['usersignature'] = $checkinfo->usersignature;
            $log['created'] = time();
            $result = Comwordsselflog::insert($log);
        }
        $urlArray = explode(',', $wordsUrl);
        foreach ($urlArray as $k => $v) {
            $download[$k]['name'] = substr(strrchr($v,'/'),1,-18);
            $download[$k]['url'] = substr($v,1);
        }
        return view('ninecheckself/download')
            ->with('download',$download);
    }

    /**
     * 生成检测报告
     *
     **/
    protected function exportWord($companyId)
    {
        $company = Company::find($companyId);
	    $user = Auth::user();
	    //检查情况
	    $comcheck = new Comcheckself();
        $checkinfo = $comcheck->where(['companyId'=>$companyId])->first();
        //负面清单
	    $comCheckdetail = new Comcheckdetailself();
        $checkdetail = $comCheckdetail->getCheckDetail($companyId);

        $comName = $company->comName;
//        $created = date('Ymdhi',strtotime($checkinfo->created));
        $created = '';
        $address = [];
        $address['city'] = Area::find($company->city)->name;
        $address['district'] = Area::find($company->district)->name;
        $address['street'] = Area::find($company->street)->name;
        $templateProcessor =  new TemplateProcessor('./word/notice.docx');
        $docName = $comName.'隐患告知单_' . $created;
        $wordClass = WordChoose::choose($templateProcessor,'notice');
	    $checkDataClass = new WordcheckdataselfClass();
	    $wordData = $checkDataClass->createNotice($company,$checkinfo,$checkdetail,$address);
	    $data = $wordData['data'];
	    $imgData = $wordData['imgData'];
        $wordClass->set($data,$imgData);
        $noticeUrl = $wordClass->create(date('Ymd', time()),$docName);
        //检查报告
        $checkProcessor =  new TemplateProcessor('./word/report.docx');
        $safeoffer = Comsafeofficer::where(['companyId' => $companyId])->first();
        $docName = $comName.'检查报告_' . $created;
        $wordClass = WordChoose::choose($checkProcessor,'notice');
        $reportData = $checkDataClass->createExport($company,$checkinfo,$user,$checkdetail,$safeoffer,$address);
        $report = $reportData['data'];
        $reportImg = $reportData['reportImg'];
        $wordClass->set($report,$reportImg);
	    $reportUrl = $wordClass->create(date('Ymd', time()),$docName);
        /*公司安全管理信息*/
        $safe_users = Comsafeofficer::where(['companyId'=>$companyId])->get();

        /*导出word*/
        $templateFireProcessor =  new TemplateProcessor('./word/青岛青科安全检查记录表（消防安全类）.docx');
        $templateUnfireProcessor = new TemplateProcessor('./word/青岛青科安全检查记录表（生产安全类）.docx');
	    $exportData = $checkDataClass->createRecord($company,$checkinfo,$user,$checkdetail,$safe_users,$address);
	    $exportLogData = $exportData['exportLogData'];
	    $exportFireLogData = $exportData['exportFireLogData'];
	    $exportUnFireLogData = $exportData['exportUnFireLogData'];
        $docFireName = $comName.'青岛青科安全检查记录表（消防安全类）_' . $created;
        $wordFireClass = WordChoose::choose($templateFireProcessor,'nineCheckAgainLog');
	    $wordFireClass->set($exportLogData,$exportFireLogData);
        $wordFireUrl = $wordFireClass->create(date('Ymd', time()),$docFireName);
        $docUnfireName = $comName.'青岛青科安全检查记录表（生产安全类）_' . $created;
        $wordUnFireClass = WordChoose::choose($templateUnfireProcessor,'nineCheckAgainLog');
        $wordUnFireClass->set($exportLogData,$exportUnFireLogData);
        $wordUnfireUrl = $wordUnFireClass->create(date('Ymd', time()),$docUnfireName);

        $comcheckgroup = new Comcheckgroupself();
        $checkGroupInfo = $comcheckgroup->getCheckgroupByComcheck($checkinfo->id, 1);
        $riskData = $checkDataClass->createRisk($company,$checkinfo,$checkdetail,$checkGroupInfo,$address);
        $riskPointArr = $riskData['riskPointArr'];
        $riskPoints = $riskData['riskPoints'];
        $templateRiskPointProcessor = new TemplateProcessor('./word/青岛青科安全生产风险点名册.docx');
        $docRiskPointName = $comName.'安全生产风险点名册_' . $created;

        $wordRiskPointClass = WordChoose::choose($templateRiskPointProcessor,'risk');

        $wordRiskPointClass->set($riskPointArr,$riskPoints);

        $wordRiskPointUrl = $wordRiskPointClass->create(date('Ymd', time()),$docRiskPointName);
        /*保存word文档路径*/
        $checkinfo->wordsUrl = $noticeUrl.','.$reportUrl.','.$wordUnfireUrl.','.$wordFireUrl.','.$wordRiskPointUrl;

        return $checkinfo->wordsUrl;
        // return redirect($wordUrl);
        // return response()->download($wordUrl);
    }

}
